#include "program.h"
#include <QObject>
#include "person.h"
#include <QObject>
#include "iostream"
#include "sstream"
#include "vector"
using namespace std;
using std::ios;
using std::vector;
Program::Program(QObject *parent) : QObject(parent)
{

}
Program::Program(QString id,QString na,QString ty, QString mas,QString fie,QString star,
        float mon,vector<QString> peo,bool ag ,float virmon ,QString remar ,int sta ) ///普通用户项目申报
{
    ID = id;
    name = na;
    type = ty;
    master = mas;
    people = peo;
    field = fie;
    startime = star;
    money = mon;
    status= sta;
    ifagree = ag;
    virmoney = virmon;
    remarks = remar;
}
void Program::setstatus (int s) ///用于root用户同意项目申请或者用户结题
{
    status = s;
}
bool Program::ifover ()      ///返回1，表示项目已经完成，返回0，表示项目没有完成
{
    if(status==1)
    return 1;
    else
    return 0;
}
int Program::showstatus ()
{
    return status;
}
void Program::addpeo(QString id) ///添加新的研究人员
{
    people.push_back(id);
}
bool Program::ifhere(QString name){
    for(unsigned int i=0;i<people.size();i++){
        if(people[i]==name){
            return 1;
        }
    }
    return 0;
}
float Program::showmoney ()
{
    return money;
}
void Program::addmoney(float a)
{
    virmoney += a;
}
float Program::showvmoney(){
    return virmoney;
}
void Program::clearvirmoney(){
    virmoney=0;
}
bool Program::ifaskmoney ()///返回1，表示要钱
{
    if(virmoney!=0)
        return 1;
    else return 0;
}
void Program::givemoney()
{
    money+=virmoney;
    virmoney = 0;
}
QString Program::showid()
{
    return ID;
}
QString Program::showname()
{
    return name;
}
QString Program::showtype()
{
    return type;
}
QString Program::showmaster()
{
    return master;
}
QString Program::showfield()
{
    return field;
}
QString Program::showtime()
{
    return startime;
}
bool Program::iftogether (QString peo1, QString peo2) ///判断两个人是否在同一个项目中
{
    int i=0;
    int j=people.size();
    for (int m=0;m<j;m++){
        if(people[m]==peo1)
            i++;
        if(people[m]==peo2)
            i++;
    }
    if(i==2)
        return 1;
    else
        return 0;
}
bool Program::ifhave(QString mes)
{
    if(mes==ID||mes==name)
        return  1;
    else return 0;
}
QString Program::showrem()
{
    return remarks;
}
void Program::save(ostringstream& os){                            ///保存
int r=0;
os<<ID.toStdString()<<endl<<name.toStdString()<<endl<<type.toStdString()<<endl<<master.toStdString()<<endl<<field.toStdString()<<endl<<startime.toStdString()<<endl<<money<<endl;
for(unsigned int i=0;i<people.size();i++){
    if(r==0){
        os<<people[i].toStdString();
        r=1;
    }
    else{
        os<<","<<people[i].toStdString();
    }
}
os<<endl<<ifagree<<endl<<virmoney<<endl<<remarks.toStdString()<<endl<<status<<endl;
}
void Program::agree (bool i)
{
    ifagree =i;
}
bool Program::agreeornot()
{
    return  ifagree;
}
